//
//  MonthMenuView.m
//  AroundTheWorld
//
//  Created by dllo on 16/5/26.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "MonthMenuView.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#import "MonthMenuViewTabviewCell.h"
#import "DataHandler.h"
#import "FindTravellingMenuModel.h"
#import "FindTravellingMenuTimes_rangeModel.h"

@implementation MonthMenuView

- (void) showinView
{
    self.backgroundColor = [UIColor clearColor];
    [self getData];
   
    UIView *backV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    backV.backgroundColor = [UIColor blackColor];
    backV.alpha = 0.3;
    [self addSubview:backV];
    
    self.myTabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 260) style:UITableViewStylePlain];
    self.myTabelView.backgroundColor = [UIColor whiteColor];
        self.myTabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:self.myTabelView];
    self.myTabelView.showsVerticalScrollIndicator = NO;
    
    //成为代理人
    self.myTabelView.delegate = self;
    self.myTabelView.dataSource = self;
    
    //注册
    [self.myTabelView registerClass:[MonthMenuViewTabviewCell class] forCellReuseIdentifier:@"reuse"];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(10, 90, WIDTH - 20, 1)];
    view1.backgroundColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:1.0];
    [self.myTabelView addSubview:view1];
    
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 310, WIDTH - 20, 1)];
    view2.backgroundColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:1.0];
    [self.myTabelView addSubview:view2];
}
//data
-(void)getData{
    self.myArrayM = [NSMutableArray array];
    self.myTimesArrayM = [NSMutableArray array];
    self.myCityArrayM = [NSMutableArray array];
    self.myTimesBXArrayM =[NSMutableArray array];
    self.myTimesHolidayArrayM =[NSMutableArray array];
    self.myTimesMonthArrayM =[NSMutableArray array];
    
    DataHandler *handler1 = [[DataHandler alloc] init];
    [handler1 getCommunityFindTravellMenuBase: ^(id result) {
        self.myArrayM = [NSMutableArray arrayWithArray:result];
        FindTravellingMenuModel *model = [self.myArrayM objectAtIndex:0];
        self.myTimesArrayM = model.times_range;
        self.myCityArrayM = model.destination;
        //1.
        [self.myTimesBXArrayM  addObject:[self.myTimesArrayM objectAtIndex:0]];
        //2.
        NSMutableArray *array = [NSMutableArray array];
        for (int i = 1; i < 8; i++) {
            FindTravellingMenuTimes_rangeModel *model = [self.myTimesArrayM objectAtIndex:i];
            [array addObject:model];
        }
        self.myTimesMonthArrayM = [NSMutableArray arrayWithArray:array];
        //3
        NSMutableArray *array2 = [NSMutableArray array];
        for (int i = 8; i < self.myTimesArrayM.count; i++) {
            FindTravellingMenuTimes_rangeModel *model = [self.myTimesArrayM objectAtIndex:i];
            [array2 addObject:model];
        }
        self.myTimesHolidayArrayM = [NSMutableArray arrayWithArray:array2];
         [self.myTabelView reloadData];
    } failedHandler:^(NSError *error) {
    }];
}
//cell高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 105;
    }
    if (indexPath.row == 1) {
        return 220;
    }
    return 155;
}

//cell数
- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

//建cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        MonthMenuViewTabviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
        cell.myModelArray = self.myTimesBXArrayM;
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.row == 1) {
        MonthMenuViewTabviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
        cell.myModelArray = self.self.myTimesMonthArrayM;
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
        return cell;
    }
    MonthMenuViewTabviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.myModelArray = self.myTimesHolidayArrayM;
     cell.selectionStyle =UITableViewCellSelectionStyleNone;
    return cell;
}

//点击方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}





/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
